<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>我的日志</title>
		<link type="text/css" rel="stylesheet" href="../jquery-easyui-1.4.2/themes/default/easyui.css">
		<link type="text/css" rel="stylesheet" href="../jquery-easyui-1.4.2/themes/icon.css">
		<script type="text/javascript" src="../js/jquery-2.1.1.min.js"></script>
		
		<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css" />
		<script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
		
		<script type="text/javascript" src="../jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="../js/dateFormat_CY.js"></script>
		<script type="text/javascript">
			//按条件组合搜索
			function searchLog(){
				var logType = $("#input_logType").combo('getValue');
    			var keyword = $("#input_keyword").val();
    			var fromDate = $("#input_fromDate").datebox('getValue');
    			var toDate = $("#input_toDate").datebox('getValue');
				$('#dg').datagrid('load',
						{pageNo:1, pageSize:10,logType:logType,keyword:keyword,
					fromDate:fromDate,toDate:toDate});
			};

			//加载组合条件查询的下拉数据
			$(function(){
				$('#perWin').window('close'); 
				//加载分类的数据
				$.post("../log/loadLogType.do",function(data){
					$('#input_logType').combobox({  
						data:data,
						editable:false,
					    valueField:'typeId',    
					    textField:'logTypeName'   
					}); 
				},"json");
			});
			$(function(){
				//加载表格渲染数据
				$('#dg').datagrid({    
				    url:'../log/loadAllMyLogById.do?userId=<%=request.getParameter("userId")%>',
				    pagination:true,
				    rownumbers:true,
				    striped:true,
				    queryParams:{pageNo:1,pageSize:10,logType:-1,keyword:"",
				    	fromDate:"",toDate:""},
				    frozenColumns:[[{field:"checkboxes",width:50,checkbox:true}]],
				    columns:[[   
						{field:'logId',title:'日志Id',width:100,hidden:true},
				        {field:'logTitle',title:'标题',width:100,align:'center'},    
				        {field:'typeName',title:'类别',width:100,align:'center'}, 
				        {field:'userName',title:'姓名',width:100,align:'center'},    
				        {field:'logDateTime',title:'日期',width:120,
				        	align:'center',formatter:formatDateBoxFull },
				        {field:'logContext',title:'内容',width:500,align:'center'}
				    ]]    
				});
				$('#dg').datagrid({
					toolbar: '#tb'
				});
				var page = $('#dg').datagrid('getPager');
				page.pagination({
					onSelectPage:function(pageNumber, pageSize){
						$('#dg').datagrid('load',{pageNo:pageNumber, pageSize:pageSize});
						page.pagination({
							pageNumber:pageNumber,
							pageSize:pageSize,
							logType:-1,
							keyword:"",
							fromDate:"",
							toDate:""
						});
					}
				});
			});
			
			//给指定日志设置查看权限
			function permission(){
				var selections = $("#dg").datagrid("getSelections");
    			if(selections.length ==0){
    				$.messager.alert('错误','请选择要修改的用户信息');
    				return ;
    			}
    			if(selections.length >1){
    				$.messager.alert('错误','请选择一条数据要修改的用户信息');
    				return ;
    			}
    			var logId = selections[0].logId;
    			//有权限查看这篇日志用户
    			$.post("../log/log_permissionUser.do",{logId:logId},function(data){
    				$("#left").html("");
    				var json = eval(data);
    				$.each(json,function(index,item){
	    				$("#left").append("<option value='"+json[index].userId+"'>"+json[index].userName+"</option>");
    				});
    			},"json");
    			
    			//没有权限查看这篇日志用户
    			 $.post("../log/log_permissionOutUser.do",{logId:logId},function(data){
    				$("#right").html("");
    				var json = eval(data);
    				$.each(json,function(index,item){
    					$("#right").append("<option class='op' value ='"+json[index].userId+"'>"+json[index].userName+"</option>");
    					
    					//$("#right").append("<optgroup class='menu' expand='0' label='"+json[index].deptName+"'><option class='op' value ='"+json[index].userId+"'>"+json[index].userName+"</option></optgroup>");
    				});
    			},"json");
    			$('#perWin').window('open');  // open a window 
			};
			/* $(function(){
				$("body").on('click','.menu',function(e){
					//e.stopPropagation();
					if($(this).attr("expand")==0){
						$(this).find("option").show();
						$(this).attr("expand","1");
					}else{
						$(this).find("option").hide();
						$(this).attr("expand","0");
					}
					return false; 
				});
				$("body").on("click",".op",function(e){
					return false;
				});
			}); */
			$("#left-btn1").bind("click",function(){
				var num = $("#left option:selected").html();
				$("#right").append("<option>"+num+"</option>");
				$("#left option:selected").remove();
			}),
			$("#left-btn2").bind("click",function(){
				$("#left option").appendTo("#right");
			}),
			$("#right-btn1").bind("click",function(){
				var num = $("#right option:selected").html();
				$("#left").append("<option>"+num+"</option>");
				$("#right option:selected").remove();
			}),
			$("#right-btn2").bind("click",function(){
				$("#right option").appendTo("#left");
			})
		</script>
	
	</head>
	<body>
		
		<!--添加工具栏按键，增删编辑和组合查询-->
		<div id="toolbar" class="row" style="margin-top: 30px;">
			
			<div class="col-md-3 col-lg-offset-1" >
				<span>关键字:</span>
		  		<input id="input_keyword" style="border-radius: 5px;border-color: #9ACFEA;height: 30px;width: 200px;" type="text" placeholder="请输入内容的关键字" >
			</div>
			<div class="col-md-3" >
			  	<span>类别:</span>
				<select id="input_logType" class="easyui-combobox" name="input_logType" style="height: 30px;width: 200px;"></select>
			</div>
		</div>
		<div class="row" style="margin-top: 20px;">
			<div class="col-md-3 col-lg-offset-1" >
				<span>&nbsp;&nbsp;日  期:</span>
		  		<input id="input_fromDate" type="text" style="height: 30px;width: 200px;" class="easyui-datebox">
			</div>
			<div class="col-md-3" >
		  		<span>&nbsp;&nbsp;&nbsp;至:</span>
		  		<input id="input_toDate" type="text" style="height: 30px;width: 200px;" class="easyui-datebox">
			</div>
			<div class="col-md-3" >
				<a id="btn" href="javascript:searchLog();" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a> 
			</div>
		</div>
		<table id="dg"></table>

		<div id="tb">
			<a href="javascript:permission();" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" >设置权限</a>
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-help'" ></a>
		</div>
		
		<div id="perWin" class="easyui-window" title="设置权限" style="width:600px;height:400px"
			 data-options="iconCls:'icon-save',modal:true" >
			 <div class="row">
			 	<div class="col-md-4">
					<select  id="left" size="10" style="width:200px;height:200px;"></select>
				</div>
				
				<div id="div2" class="col-md-4"   style="width:200px;height:200px;">
					 <select  id="right" size="10" style="width:200px;height:200px;">
								<!-- <optgroup class="menu" expand="0" > -->
							 <!-- <optgroup class="menu" expand="0" label="个人信息">
							    <option value ="volvo">英语</option>
							  </optgroup>
							
							  <optgroup class="menu" expand="0" label="成绩">
							    <option value ="mercedes">英语</option>
							  </optgroup> -->
					 </select> 
				</div>
			</div>
			<div class="row">
				<div class="col-md-offset-3">
					<p>
						<input type="button" id="left-btn1" value="&gt" />
						<input type="button" id="left-btn2" value="&gt&gt" />
						<input type="button" id="right-btn1" value="&lt" />
						<input type="button" id="right-btn2" value="&lt&lt" />
					</p>
				</div>
			</div>
		</div>
		
	</body>
</html>

